/*
 *  档案门类 API接口
 * :
 * @version: 1.0
 * @Autor: lakeside hubin_yuan.410@hotmail.com
 * @date: 20120-07-14
 * @LastEditors:
 * @LastEditTime:
 */

import {_axios, urlParamStringify} from '@/plugins/axios'
import {stringFormat} from '@/utils/modules/common'

const apiPrefix = '/dossier/category'

/**
 * 请求URL
 */
export const const_url = Object.freeze({
    count: apiPrefix + '/count',
    find: apiPrefix + '/{{idArr}}',
    page: apiPrefix + '/page',
    list: apiPrefix + '/list',
    remove: apiPrefix + '/{{idArr}}',
    save: apiPrefix + '/save',
    patch: apiPrefix + '/{{idArr}}',
})

/**
 * 数量查询信息
 */
export async function count(requestParam, config) {
    let requestUrl = const_url.count + "?" + urlParamStringify(requestParam)
    return await _axios.get(requestUrl, config)
}

/**
 *获取对象信息
 * pathVariable 其中必须包括idArr
 * requestParam
 */
export async function find(pathVariable, requestParam, config) {
    let requestUrl = stringFormat(const_url.find, pathVariable) + "?" + urlParamStringify(requestParam)
    return await _axios.get(requestUrl, config)
}

/**
 * 分页查询信息
 * requestParam
 */
export async function page(requestParam, config) {
    let requestUrl = const_url.page + "?" + urlParamStringify(requestParam)
    return await _axios.get(requestUrl, config)
}

/**
 * 全量查询信息
 * requestParam
 */
export async function list(requestParam, config) {
    let requestUrl = const_url.list + "?" + urlParamStringify(requestParam)
    return await _axios.get(requestUrl, config)
}

/**
 * 保存实体信息（全量插入<jpa:存在id时即为更新>）
 * requestBody 可以是数组或者单个实体
 */
export async function save(requestBody, config) {
    return await _axios.post(const_url.save, requestBody, {
        ...config, headers: {
            'Content-Type': 'application/json'
        }
    })
}

/**
 * 批量更新实体的字段信息(更新面向字段，未传字段不更新)
 * pathVariable 其中必须包括idArr
 * requestBody 其中不能包括id
 */
export async function patch(pathVariable, requestBody, config) {
    let requestUrl = stringFormat(const_url.patch, pathVariable)
    return await _axios.put(requestUrl, requestBody, {
        ...config, headers: {
            'Content-Type': 'application/json'
        }
    })
}

/**
 * 批量逻辑删除信息
 * pathVariable 其中必须包括idArr
 * requestParam 其中必须包括 deleteMode
 */
export async function remove(pathVariable, requestParam, config) {
    let requestUrl = stringFormat(const_url.remove, pathVariable) + "?" + urlParamStringify(requestParam)
    return await _axios.delete(requestUrl, config)
}